package com.dormitory_springboot.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dormitory_springboot.entity.Dormitory;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author admin
 * @since 2022-06-01
 */
@Repository
@Mapper
public interface DormitoryMapper extends BaseMapper<Dormitory> {


    @Update("UPDATE dormitory SET available = available - 1 WHERE id = #{dormitoryId}")
    void subAvailable(Integer dormitoryId);

    @Update("UPDATE dormitory SET available = available + 1 WHERE id = #{id}")
    void addAvailable(Integer id);

    Integer findAvailableDormitoryId();

    @Select("SELECT * FROM dormitory WHERE building_id = #{buildingId}")
    List<Dormitory> selectDormitoriesByBuildingId(@Param("buildingId") Integer buildingId);

    @Update("UPDATE dormitory SET available = type WHERE building_id = #{buildingId}")
    void updateAvailableToType(String buildingId);

    @Select("SELECT * FROM dormitory WHERE building_id = #{buildingId}")
    List<Dormitory> getDormitoriesByBuildingId(String buildingId);

}
